package com.tdkj.action.front.enterpriseZone;

import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.tdkj.action.BaseAction;
import com.tdkj.model.enterprisezone.BeanEnterprise;
import com.tdkj.model.enterprisezone.BeanEnterpriseNews;
import com.tdkj.model.enterprisezone.BeanEnterpriseProduct;
import com.tdkj.model.enterprisezone.BeanEnterpriseZone;
import com.tdkj.model.enterprisezone.BeanEnterpriseZoneComment;
import com.tdkj.model.enterprisezone.BeanEnterpriseZoneDecorate;
import com.tdkj.model.enterprisezone.BeanEnterpriseZoneFriendsLink;
import com.tdkj.model.enterprisezone.BeanEnterpriseProductClass;
import com.tdkj.model.enterprisezone.BeanEnterpriseZoneVisitor;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.enterprisezone.IBeanEnterpriseNewsService;
import com.tdkj.service.enterprisezone.IBeanEnterpriseProductService;
import com.tdkj.service.enterprisezone.IBeanEnterpriseService;
import com.tdkj.service.enterprisezone.IBeanEnterpriseZoneCommentService;
import com.tdkj.service.enterprisezone.IBeanEnterpriseZoneFriendsLinkService;
import com.tdkj.service.enterprisezone.IBeanEnterpriseProductClassService;
import com.tdkj.service.enterprisezone.IBeanEnterpriseZoneVisitorService;
import com.tdkj.service.user.IBeanUserService;
import com.tdkj.util.PublicConfing;

public class CommentAction extends BaseAction {
	private BeanUser user; //当前登陆用户
	private BeanUser zoneUser;
	private BeanEnterprise enterprise;
	private BeanEnterpriseZone zone;
	private String commentContent;
	
	private IBeanUserService userService;
	private IBeanEnterpriseService enterpriseService;

	private List<BeanEnterpriseZoneComment> commentList;
	private IBeanEnterpriseZoneCommentService commentService;
	
	@Override
	public String execute(){
		String zoneUserId = ServletActionContext.getRequest().getParameter("zoneuserid");
		user = (BeanUser) ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		
		if(zoneUserId != null && !"".equals(zoneUserId) ){
			zoneUser = userService.getUser(Long.valueOf(zoneUserId));
		}else if(user != null){
			zoneUser =	user; 
		}else{
			////跳404
		}
		zone = zoneUser.getEnterpriseZone();
		
		commentList = commentService.findByProperty("enterpriseZone", zone, BeanEnterpriseZoneComment.class);
		return this.SUCCESS;
	}
	
	public String addComment(){
		String zoneUserId = ServletActionContext.getRequest().getParameter("zoneuserid");
		user = (BeanUser) ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		
		if(zoneUserId != null && !"".equals(zoneUserId) ){
			zoneUser = userService.getUser(Long.valueOf(zoneUserId));
		}else if(user != null){
			zoneUser =	user; 
		}else{
			////跳404
		}
		zone = zoneUser.getEnterpriseZone();
		BeanEnterpriseZoneComment comment = new BeanEnterpriseZoneComment();
		comment.setContent(commentContent);
		comment.setEnterpriseZone(zone);
		comment.setUser(user);
		comment.setPostTime(new Timestamp(System.currentTimeMillis()));
		commentService.save(comment);
		commentContent = "";
		commentList = commentService.findByProperty("enterpriseZone", zone, BeanEnterpriseZoneComment.class);
		return this.SUCCESS;
	}
	
	
	public String getCommentContent() {
		return commentContent;
	}

	public void setCommentContent(String commentContent) {
		this.commentContent = commentContent;
	}

	public BeanUser getZoneUser() {
		return zoneUser;
	}

	public void setZoneUser(BeanUser zoneUser) {
		this.zoneUser = zoneUser;
	}

	public BeanUser getUser() {
		return user;
	}

	public void setUser(BeanUser user) {
		this.user = user;
	}

	public BeanEnterpriseZone getZone() {
		return zone;
	}

	public void setZone(BeanEnterpriseZone zone) {
		this.zone = zone;
	}

	public BeanEnterprise getEnterprise() {
		return enterprise;
	}

	public void setEnterprise(BeanEnterprise enterprise) {
		this.enterprise = enterprise;
	}

	public List<BeanEnterpriseZoneComment> getCommentList() {
		return commentList;
	}

	public void setCommentList(List<BeanEnterpriseZoneComment> commentList) {
		this.commentList = commentList;
	}
	
	@Resource
	public void setEnterpriseService(IBeanEnterpriseService enterpriseService) {
		this.enterpriseService = enterpriseService;
	}


	@Resource
	public void setUserService(IBeanUserService userService) {
		this.userService = userService;
	}



	@Resource
	public void setCommentService(IBeanEnterpriseZoneCommentService commentService) {
		this.commentService = commentService;
	}
}
